﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class FundsDAL : PageDAL<FundsModel>
    {
        public DataTable  A()
        {
            string sql = "select * from funds where id = (select max(id) from Funds)";
            return new DBHelper().GetDataTable(sql);
         }
        public bool OGai(int pid)
        {
            string sql = $"update Funds set EMoney=EMoney+(select Money from Funds where OrdersID={pid}) where ID>(select ID from Funds where OrdersID={pid})";
            return new DBHelper().Zsg(sql);
        }
        public bool OD(int pid)
        {
            string sql = $"delete Funds where ID=(select ID from Funds where OrdersID={pid})";
            return new DBHelper().Zsg(sql);
        }
        public bool SD(int pid)
        {
            string sql = $"delete Funds where ID=(select ID from Funds where SalesID={pid})";
            return new DBHelper().Zsg(sql);
        }
        public bool SGai(int pid)
        {
            string sql = $"update Funds set EMoney=EMoney-(select Money from Funds where salesID={pid}) where ID>(select ID from Funds where salesID={pid})";
            return new DBHelper().Zsg(sql);
        }
    }
    }
